<script lang="ts">
import { defineComponent } from "vue";

export default defineComponent({
  props: {
    info: { type: Object, required: true },
    isCertificate: Boolean,
  },
});
</script>

<template>
  <view class="course-item">
    <view class="course-item-cover">
      <image class="course-item-img" :src="info.cover_img" mode="aspectFill" />
      <image
        class="course-item-lock"
        v-if="info.is_certification === 1 && !isCertificate"
        src="/static/study-course-lock.png"
      />
    </view>
    <view class="course-item-content">
      <view class="course-item-name">{{ info.title }}</view>
      <view style="display: flex; align-items: center">
        <view class="course-item-tag">{{ info.total_course }}节课</view>
        <view class="course-item-free" v-if="info.price_type === 0">免费</view>
        <view class="course-item-price" v-else>
          ¥{{ info.price }}<text class="course-item-price2">起</text>
        </view>
      </view>
    </view>
  </view>
</template>

<style lang="scss">
.course-item {
  border-radius: 20rpx;
  background-color: #ffffff;

  .course-item-cover {
    position: relative;
  }

  .course-item-img {
    display: block;
    width: 100%;
    height: 178rpx;
    border-radius: 20rpx 20rpx 0 0;
  }

  .course-item-lock {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 56rpx;
    height: 56rpx;
    transform: translate(-50%, -50%);
  }

  .course-item-content {
    padding: 20rpx;
  }

  .course-item-name {
    margin-bottom: 10rpx;
    font-size: 28rpx;
    color: #2d2d2d;
    line-height: 42rpx;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }

  .course-item-tag {
    padding: 0 10rpx;
    font-size: 20rpx;
    color: #ffa300;
    line-height: 32rpx;
    border-radius: 8rpx;
    background-color: rgba(255, 203, 110, 0.2);
  }

  .course-item-free {
    margin-left: auto;
    padding-top: 6rpx;
    font-size: 26rpx;
    color: #fa6400;
    line-height: 36rpx;
    font-weight: bold;
  }

  .course-item-price {
    margin-left: auto;
    font-size: 30rpx;
    color: #fa6400;
    line-height: 42rpx;
    font-weight: bold;
  }

  .course-item-price2 {
    margin-left: 2rpx;
    font-size: 20rpx;
    color: #666666;
    font-weight: 400;
  }
}
</style>